package cn.tedu.boyou.mgrsite.controller;

import cn.tedu.boyou.acticle.domain.Destination;
import cn.tedu.boyou.acticle.domain.Region;
import cn.tedu.boyou.acticle.service.IDestinationService;
import cn.tedu.boyou.acticle.service.IRegionService;
import cn.tedu.boyou.common.query.RegionQuery;
import cn.tedu.boyou.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/region")
public class RegionController {

    @Reference
    private IRegionService regionService;
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo")RegionQuery qo){
        model.addAttribute("pageInfo",regionService.query(qo));
        return "region/list";
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){
        List<Destination> destinations = destinationService.getDestByDeep(deep);
        return destinations;
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){
        regionService.saveOrUpdate(region);
        return new AjaxResult();
    }

    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(Long rid){
        return destinationService.queryDestByRegionId(rid);
    }

    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(Long id,Boolean hot){
        regionService.changeHotValue(id ,hot);
        return new AjaxResult();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        regionService.delete(id);
        return new AjaxResult();
    }


}
